package com.jerry.passenger.account.presenter;

import com.jerry.passenger.account.model.IUserManager;
import com.jerry.passenger.account.model.response.LoginResponse;
import com.jerry.passenger.account.view.ILoginView;
import com.jerry.passenger.common.databus.RegisterBus;

public class LoginDialogPresenterImpl implements ILoginDialogPresenter {

    private ILoginView view;
    private IUserManager userManager;

    /**
     * 接收子线程消息
     */
    @RegisterBus
    public void onLoginResponse(LoginResponse loginResponse) {
            // 处理UI 变化
            switch (loginResponse.getCode()) {
                case IUserManager.LOGIN_SUC:
                    // 登录成功
                    view.showLoginSuc();
                    break;
                case IUserManager.PW_ERROR:
                    // 密码错误
                    view.showError(IUserManager.PW_ERROR, "");
                    break;
                case IUserManager.SERVER_FAIL:
                    // 服务器错误
                    view.showError(IUserManager.SERVER_FAIL, "");
                    break;
            }

    }

    public LoginDialogPresenterImpl(ILoginView view,
                                    IUserManager userManager) {
        this.view = view;
        this.userManager = userManager;
    }


    @Override
    public void requestLogin(String phone, String password) {
        userManager.login(phone, password);
    }

}
